﻿using IdentityModel.Client;
using Newtonsoft.Json.Linq;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace SJ.Platform.Common
{
    /// <summary>
    /// 接口操作类
    /// </summary>
    public class InterfaceHandle
    {
        public static async Task<string> PostAsync(string baseUrl,string resource, string token, string body)
        {
            try
            {
                var options = new RestClientOptions(baseUrl);
                var client = new RestClient(options);
                var request = new RestRequest(resource, Method.Post);
                request.AddHeader("Authorization", "Bearer " + token);

                request.AddParameter("application/json", body, ParameterType.RequestBody);
                var response = await client.ExecuteAsync(request);
                return response.Content;//{"data":true,"code":"200","message":"操作记录添加成功"}
            }
            catch (Exception ex)
            {
                return "{  code:404 ,data: '',msg: '" + ex.Message + "'}";
            }
        }
    }
}
